global class DeleteNCMainData implements Schedulable {
    global void execute(SchedulableContext sc) {
        // 出库单
        // Map<Id, AggregateResult> exMap = new Map<Id, AggregateResult>([
        //         select count(Id) Cnt_Id, ExWarehouse__c Id
        //           from ExWarehouse_Detail__c
        //          group by ExWarehouse__c
        // ]);
        // List<ExWarehouse__c> delExList = new List<ExWarehouse__c>();
        // for (AggregateResult ar : exMap.values()) {
        //     Integer cnt = Integer.valueOf(ar.get('Cnt_Id'));
        //     // 如果cnt=0（没有明细数据），那就删除主表
        //     if (cnt == 0) {
        //         delExList.add(new ExWarehouse__c(Id = String.valueOf(ar.get('Id'))));
        //     }
        // }
        // if (delExList.size() > 0) delete delExList;

        //DetailSize__c是个累计汇总字段，统计了出库单明细的个数。这里删除了个数为0的出库单。
        delete [SELECt Id FROM ExWarehouse__c WHERE DetailSize__c = 0];
        delete [SELECt Id FROM Order__c WHERE OrderProductAmmount__c = 0];
        delete [SELECt Id FROM Sales_Invoice__c WHERE DetailSize__c = 0];
    }
}